package com.ha.mapper;

import com.github.pagehelper.Page;
import com.ha.annotation.AutoFillU;
import com.ha.dto.UserPageDTO;
import com.ha.entity.User;
import com.ha.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * ClassName: UserMapper
 * Package: com.ha.mapper
 * Description:
 *
 * @Author 那啥啥
 * @Create 2024/4/22  21:22
 * @Version 1.0
 */
@Mapper
public interface UserMapper {


    @Select("select *from  users where username = #{username}")
     User getByUsername(String username) ;

    Page<User> pageQuery(UserPageDTO userPageDTO);

    @AutoFillU(OperationType.INSERT)
    @Insert("insert into users(name, username, password, sex, phone, deleted," +
            " create_time, update_time, credit_point, max_credit_point, address) values " +
            "(#{name},#{username},#{password},#{sex},#{phone},#{deleted}," +
            "#{createTime},#{updateTime},#{creditPoint},#{maxCreditPoint},#{address})")
    void addUser(User user);

    @AutoFillU(OperationType.UPDATE)
    void update(User user);

    @Select("select *from users where   id = #{id}")
    User getById(Long id);

    @Update("update users set deleted = #{deleted} where id = #{id} ")
    @AutoFillU(OperationType.UPDATE)
    void delete(Integer deleted ,Long id);
}
